# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=openwsman
pkgver=2.7.2
pkgrel=5
pkgdesc="Opensource Implementation of WS-Management"
url="https://openwsman.github.io"
arch="all"
license="custom BSD-3-Clause"
options="!check"  # No test suite
makedepends="
	cmake
	curl-dev
	libxml2-dev
	openssl-dev
	perl-dev
	py3-setuptools
	python3-dev
	sblim-sfcc-dev
	swig
	"
subpackages="$pkgname-dev $pkgname-doc $pkgname-libs"
source="$pkgname-$pkgver.tar.gz::https://github.com/Openwsman/openwsman/archive/v$pkgver.tar.gz
	fix-musl-build.patch
	default-config.patch
	"

# secfixes:
#   2.6.10-r0:
#     - CVE-2019-3833
#   2.6.4-r0:
#     - CVE-2016-2183

build() {
	cmake -B build \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_C_FLAGS="$CFLAGS $CPPFLAGS" \
		-DCMAKE_CXX_FLAGS="$CFXXLAGS $CPPFLAGS" \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DPACKAGE_ARCHITECTURE=$CARCH \
		-DLIB=lib \
		-DUSE_PAM=NO \
		-DBUILD_PYTHON=OFF \
		-DBUILD_PYTHON3=ON \
		-DBUILD_RUBY_GEM=OFF \
		-DBUILD_JAVA=OFF
	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	mv "$pkgdir/usr/sbin/"* "$pkgdir/usr/bin"
	rmdir "$pkgdir/usr/sbin/"
	rm "$pkgdir"/etc/pam.d/$pkgname
	rmdir "$pkgdir/etc/pam.d/"
	install -Dp -m644 COPYING "$pkgdir/usr/share/licenses/$pkgname/COPYING"
}

libs() {
	pkgdesc="$pkgname libs (aka libwsman)"

	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/* \
		"$subpkgdir"/usr/lib/
}

sha512sums="
ffd6a0d00a00b00e321b2b55e0c77326f5943ca3224eee74c706e53a1c5c44ef0e8b1cfde5d631966769eefd4e567b0db8713085b7a8b386c2871ab4ada83046  openwsman-2.7.2.tar.gz
d031a3fd5f30b71ef87d7fd9c241baf55c20953c175ab0eb6192f9971b7b8a3a9c18693fa2cd468ed7f7ef94170281b7db5e987ba1b88c92d64231e560e91542  fix-musl-build.patch
3c10cb34a0bb0d70461225c0944c0fdaf9aadba2c78ee8122dcf8b493190bc86db0252cc74a7fdb178a2d0a0c26fb3323a1cd8dce320fe21eb0ad2860e42a0f1  default-config.patch
"
